package com.camera2.local;

import android.content.Context;
import android.os.Environment;

import com.camera2.http.SendImage;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SaveImage {

	public static void saveImg(Context context, byte[] data) {
		System.out.println("保存照片到手机");

		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		Date curDate = new Date(System.currentTimeMillis());
		String str = formatter.format(curDate);
		File sdRoot = Environment.getExternalStorageDirectory();
		String dir = "/QRcode/"
				+ new SimpleDateFormat("yyyy—MM—dd").format(new Date())
				.toString() + "/";
		String fileName = 1 + "--" + str + ".jpg";

		SendImage.imagePath = sdRoot + dir + fileName;

		File mFile = new File(sdRoot, dir);

//		File mFile = new File(Environment.getExternalStorageDirectory()
//				.getAbsoluteFile() + "/QRcode");
		if (!mFile.exists()) {
			mFile.mkdir();
		}

		File pictureFile = new File(sdRoot, dir + fileName);

		try {
			FileOutputStream fos = new FileOutputStream(pictureFile);
			fos.write(data);
			fos.close();
		} catch (Exception e) {
		}

	}

}
